//
//  XLGiftViewCell.m
//  XiangLove
//
//  Created by 宋振 on 2018/7/26.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLGiftViewCell.h"

#import "XLPersonCenterTool.h"

#import "UIImage+WebP.h"

@interface XLGiftViewCell ()

@property (nonatomic, strong) UIImageView *  giftImage;

@property (nonatomic, strong) UILabel *  giftName;

@property (nonatomic, strong) UILabel *  giftNum;

@end

@implementation XLGiftViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        //设置界面
        [self setCustomeView];
    }
    
    return self;
}

#pragma mark    -   -   - 设置界面显示 -  -   -

- (void)setCustomeView
{
    //礼物图片
    self.giftImage = [[UIImageView alloc] init];
    
    [self addSubview:self.giftImage];
    
    [self.giftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.right.equalTo(self);
        make.height.equalTo(self.mas_width);
    }];
    
    //礼物名称
    self.giftName = [[UILabel alloc] init];
    
    self.giftName.text = @"小皮鞭";
    
    self.giftName.font = [UIFont fontWithName:kFontNamePFRegular size:10];
    self.giftName.textColor = [UIColor colorWithRed:17/255.0 green:17/255.0 blue:17/255.0 alpha:1];
    
    self.giftName.textAlignment = NSTextAlignmentCenter;
    
    [self addSubview:self.giftName];
    
    [self.giftName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.giftImage.mas_bottom).offset(3);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(14);
    }];
    
    //礼物个数
    self.giftNum = [[UILabel alloc] init];
    
    self.giftNum.textAlignment = NSTextAlignmentCenter;
    
    self.giftNum.text = @"x4";
    
    self.giftNum.font = [UIFont fontWithName:kFontNamePFRegular size:10];
    self.giftNum.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];
    
    [self addSubview:self.giftNum];
    
    [self.giftNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.giftName.mas_bottom);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(14);
    }];
}

- (void)layoutSubviews
{
    
    
}

-(void)setDic:(NSDictionary *)dic
{
//    [self.giftImage setImageWithURL:[NSURL URLWithString:dic[@"Url"]] placeholder:[UIImage imageNamed:@""]];
    
    //图片
    NSError *error;

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:dic[@"GiftImg"]] options:(NSDataReadingMappedIfSafe) error:&error];

    UIImage * image = [UIImage sd_imageWithWebPData:data];
                    
                    
    self.giftImage.image = image;
    
    self.giftNum.text = [NSString stringWithFormat:@"x%@",dic[@"GiftNumber"]];
    
    self.giftName.text = dic[@"GiftName"];
}



@end
